import Page
from Page import Service
from Base.Base import Base
from selenium.webdriver.common.by import By


class ServiceReservationPage(Base):
    """
    去维保首页
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.reservation_home_btn = (By.XPATH, Service.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.reservation_back_btn = (By.XPATH, Service.RESOURCE_ID.format('ivBack'))

        # 预约养车服务标题
        self.reservation_car_title_text = (By.XPATH, Page.TEXT.format("预约养车服务"))

        # 服务门店按钮
        self.reservation_service_store_btn = (By.XPATH, Service.RESOURCE_ID.format("ll_store"))

        # 服务门店标题
        self.reservation_service_title_text = (By.XPATH, Page.TEXT.format("服务门店"))

        # 服务门店名称/提示
        self.reservation_service_hint_btn = (By.XPATH, Service.RESOURCE_ID.format("shop_tv"))

        # 到店时间按钮
        self.reservation_arrival_time_btn = (By.XPATH, Service.RESOURCE_ID.format("ll_time"))

        # 到店时间标题
        self.reservation_arrival_title_text = (By.XPATH, Page.TEXT.format("到店时间"))

        # 到店时间具体时间/提示
        self.reservation_arrival_hint_btn = (By.XPATH, Service.RESOURCE_ID.format("arrive_date"))

        # 用户名显示
        self.reservation_user_name_text = (By.XPATH, Service.RESOURCE_ID.format("tv_name"))

        # 用户手机显示
        self.reservation_user_number_text = (By.XPATH, Service.RESOURCE_ID.format("tv_phone"))

        # 维保名称标题
        self.reservation_select_title_text = (By.XPATH, Page.TEXT.format("维保项目"))

        # 选择项目按钮
        self.reservation_select_project_btn = (By.XPATH, Service.reservation_project_btn.format(""))

        # 提交预约按钮
        self.reservation_submit_btn = (By.XPATH, Service.RESOURCE_ID.format("submit_order"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.reservation_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.reservation_back_btn)

    def get_car_title(self):
        """
        获取预约养车标题

        :return:获取元素
        """
        return self.find_element_o(self.reservation_car_title_text)

    def get_service_title(self):
        """
        获取门店服务名称

        :return: 获取元素
        """
        return self.find_element_o(self.reservation_service_title_text)

    def click_service_store(self):
        """
        点击服务门店按钮

        :return: None
        """
        self.click_element(self.reservation_service_store_btn)

    def click_service_hint(self):
        """
        点击服务门店提示/具体门店

        :return: None
        """
        self.click_element(self.reservation_service_hint_btn)

    def get_service_hint(self):
        """
        获取具体的门店

        :return: None
        """
        return self.find_element_o(self.reservation_service_hint_btn)

    def get_arrival_title(self):
        """
        获取服到达门店时间

        :return: 获取元素
        """
        return self.find_element_o(self.reservation_arrival_title_text)

    def click_arrival_time(self):
        """
        点击到达时间按钮

        :return: None
        """
        self.click_element(self.reservation_arrival_time_btn)

    def click_arrival_hint_time(self):
        """
        点击到达时间提示/具体时间

        :return: None
        """
        self.click_element(self.reservation_arrival_hint_btn)

    def get_user_name(self):
        """
        获取用户名称

        :return: 获取元素
        """
        return self.find_element_o(self.reservation_user_name_text)

    def get_user_number(self):
        """
        获取用户电话

        :return: 获取元素
        """
        return self.find_element_o(self.reservation_user_number_text)

    def get_select_title(self):
        """
        获取维保标题

        :return: 获取元素
        """
        return self.find_element_o(self.reservation_select_title_text)

    def click_select_project(self, index=1):
        """
        点击维保项目

        index =1
        :return: None
        """
        self.reservation_select_project_btn = (By.XPATH, Service.reservation_project_btn.format(index))
        self.click_element(self.reservation_select_project_btn)

    def click_submit(self):
        """
        点击提交按钮

        :return: None
        """
        self.click_element(self.reservation_submit_btn)

    def get_submit(self):
        """
        获取提交按钮属性

        :return: 获取元素
        """
        return self.find_element_o(self.reservation_submit_btn)

    def is_display_service_reservation(self):
        """
        是否进入维保首页界面

        :return: bool
        """
        return self.is_display(self.reservation_service_title_text)

    def is_toast_service_reservation(self):
        """
        是否提交成功

        :return: bool
        """
        return self.is_toast_exist("服务异常,请稍后重试")
